package demoMod.nanaki.patches.events.beyond;

import basemod.ReflectionHacks;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.lib.SpireReturn;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.events.beyond.WindingHalls;
import com.megacrit.cardcrawl.localization.EventStrings;
import com.megacrit.cardcrawl.vfx.cardManip.ShowCardAndObtainEffect;
import demoMod.nanaki.NanakiMod;
import demoMod.nanaki.cards.tempCards.DistantWhisper;
import demoMod.nanaki.characters.NanakiCharacter;

public class WindingHallsPatch {
    public static final String ID = NanakiMod.makeID("Winding Halls");
    private static final EventStrings eventStrings = CardCrawlGame.languagePack.getEventString(ID);
    public static final String NAME = eventStrings.NAME;
    public static final String[] DESCRIPTIONS = eventStrings.DESCRIPTIONS;
    public static final String[] OPTIONS = eventStrings.OPTIONS;

    @SpirePatch(
            clz = WindingHalls.class,
            method = "buttonEffect"
    )
    public static class PatchButtonEffect {
        public static SpireReturn<Void> Prefix(WindingHalls event, int buttonPressed) {
            if (AbstractDungeon.player instanceof NanakiCharacter) {
                int screenNum = ReflectionHacks.getPrivate(event, WindingHalls.class, "screenNum");
                if (screenNum == 0) {
                    NanakiMod.addToBot(new AbstractGameAction() {
                        @Override
                        public void update() {
                            int hpToLose = (int) Math.floor(AbstractDungeon.player.maxHealth * (AbstractDungeon.ascensionLevel >= 15 ? 0.18 : 0.125));
                            event.imageEventText.updateDialogOption(0, String.format(OPTIONS[1], hpToLose), new DistantWhisper());
                            isDone = true;
                        }
                    });
                } else if (screenNum == 1 && buttonPressed == 0) {
                    event.imageEventText.updateBodyText(DESCRIPTIONS[5]);
                    int hpToLose = (int) Math.floor(AbstractDungeon.player.maxHealth * (AbstractDungeon.ascensionLevel >= 15 ? 0.18 : 0.125));
                    AbstractDungeon.player.damage(new DamageInfo(null, hpToLose));
                    CardCrawlGame.sound.play("ATTACK_MAGIC_SLOW_1");
                    AbstractDungeon.effectList.add(new ShowCardAndObtainEffect(new DistantWhisper(), (float) Settings.WIDTH / 2.0F - 350.0F * Settings.xScale, (float)Settings.HEIGHT / 2.0F));
                    AbstractDungeon.effectList.add(new ShowCardAndObtainEffect(new DistantWhisper(), (float)Settings.WIDTH / 2.0F + 350.0F * Settings.xScale, (float)Settings.HEIGHT / 2.0F));
                    ReflectionHacks.setPrivate(event, WindingHalls.class, "screenNum", 2);
                    event.imageEventText.updateDialogOption(0, OPTIONS[3]);
                    event.imageEventText.clearRemainingOptions();
                    return SpireReturn.Return(null);
                }
            }
            return SpireReturn.Continue();
        }
    }
}
